package com.xhd.notice;

import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Vector;

import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;
import com.xhd.server.ServerConfig;
import com.xhd.xml.XMLSerializer;

public class NoticeFactory {
static NoticeFactory jm16;
HashMap jm292 = null;
private static final Log jm9;
static Class jm10;

static
{
  Class tmp3_0 = jm10;
  if (tmp3_0 == null)
  {
   
    try
    {
     NoticeFactory.jm10 = Class.forName("com.sinocc.base.notice.NoticeFactory");
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
    }
  }
  jm9 = LogFactory.getLog(tmp3_0);
}

public static NoticeFactory getFactory()
{
  if (jm16 == null)
    jm16 = new NoticeFactory();
  return jm16;
}

public static NoticeSender getSender(int paramInt)
{
  return getFactory().getInstance(paramInt);
}

private NoticeFactory()
{
  String str1 = ServerConfig.getConfFilePath("noticeconf.xml");
  File localFile = new File(str1);
  if ((!(localFile.exists())) || (!(localFile.isFile())))
    return;
  try
  {
    XMLSerializer localXMLSerializer = new XMLSerializer(new FileInputStream(localFile), false);
    Vector localVector = localXMLSerializer.getCollection("noticesender");
    if ((localVector != null) && (localVector.size() > 0))
    {
      int i = localVector.size();
      this.jm292 = new HashMap(i);
      for (int j = 0; j < i; ++j)
      {
        Hashtable localHashtable = (Hashtable)localVector.get(j);
        String str2 = (String)localHashtable.get("class");
        String str3 = (String)localHashtable.get("type");
        if ((str2 == null) || (str2.length() < 1) || (str3 == null))
          continue;
        if (str3.length() < 1)
          continue;
        try
        {
          NoticeSender localNoticeSender = (NoticeSender)Class.forName(str2).newInstance();
          localNoticeSender.setType(Integer.parseInt(str3));
          this.jm292.put(new Integer(str3), localNoticeSender);
        }
        catch (Throwable localThrowable)
        {
          jm9.error("noticeconf.xml param 'class' error:", localThrowable);
        }
      }
      jm9.info("NoticeSender count: " + this.jm292.size());
      return;
    }
    this.jm292 = null;
  }
  catch (Exception localException)
  {
    jm9.error("NoticeFactory.loadConfigFile", localException);
  }
}

public NoticeSender getInstance(int paramInt)
{
  if (this.jm292 != null)
    return ((NoticeSender)this.jm292.get(new Integer(paramInt)));
  return null;
 }
}
